package com.orm.analysis.dao;

import com.orm.analysis.model.CustOrder;
import com.orm.analysis.model.Item;
import com.orm.analysis.model.OrderDetail;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/12/13
 * Time: 11:58 AM
 * To change this template use File | Settings | File Templates.
 */
public class OrderDetailDAO extends  GenericJPADAO<OrderDetail, Integer> {

    public List<OrderDetail> list(int page, int size) {
        Query query = this.em.createQuery("from OrderDetail");
        query.setFirstResult((page - 1) * size);
        query.setMaxResults(size);
        return query.getResultList();
    }


    public OrderDetail getById(Integer id) {
        return this.em.find(OrderDetail.class, id);
    }

    @Transactional
               @Override
               public void save(OrderDetail entity) {
                    getEntityManager().persist(entity);
               }

}
